﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using Terraria.GameContent.UI.Elements;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;

namespace Terraria.ModLoader.UI
{
	// Token: 0x02000291 RID: 657
	internal class UIModBrowser : UIState
	{
		// Token: 0x170001C4 RID: 452
		// (get) Token: 0x06001A85 RID: 6789 RVA: 0x00012F2D File Offset: 0x0001112D
		// (set) Token: 0x06001A86 RID: 6790 RVA: 0x00012F35 File Offset: 0x00011135
		internal string SpecialModPackFilterTitle
		{
			get
			{
				return this._specialModPackFilterTitle;
			}
			set
			{
				this.clearButton.SetText(Language.GetTextValue("tModLoader.MBClearSpecialFilter", value));
				this._specialModPackFilterTitle = value;
			}
		}

		// Token: 0x170001C5 RID: 453
		// (get) Token: 0x06001A87 RID: 6791 RVA: 0x00012F54 File Offset: 0x00011154
		// (set) Token: 0x06001A88 RID: 6792 RVA: 0x00429DB0 File Offset: 0x00427FB0
		public List<string> SpecialModPackFilter
		{
			get
			{
				return this._specialModPackFilter;
			}
			set
			{
				if (this._specialModPackFilter != null && value == null)
				{
					this.uIPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
					this.uIElement.RemoveChild(this.clearButton);
					this.uIElement.RemoveChild(this.downloadAllButton);
				}
				else if (this._specialModPackFilter == null && value != null)
				{
					this.uIPanel.BackgroundColor = Color.Purple * 0.7f;
					this.uIElement.Append(this.clearButton);
					this.uIElement.Append(this.downloadAllButton);
				}
				this._specialModPackFilter = value;
			}
		}

		// Token: 0x06001A89 RID: 6793 RVA: 0x00429E5C File Offset: 0x0042805C
		public override void OnInitialize()
		{
			this.uIElement = new UIElement();
			this.uIElement.Width.Set(0f, 0.8f);
			this.uIElement.MaxWidth.Set(600f, 0f);
			this.uIElement.Top.Set(220f, 0f);
			this.uIElement.Height.Set(-220f, 1f);
			this.uIElement.HAlign = 0.5f;
			this.uIPanel = new UIPanel();
			this.uIPanel.Width.Set(0f, 1f);
			this.uIPanel.Height.Set(-110f, 1f);
			this.uIPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
			this.uIPanel.PaddingTop = 0f;
			this.uIElement.Append(this.uIPanel);
			this.uILoader = new UILoaderAnimatedImage(0.5f, 0.5f, 1f);
			this.modList = new UIList();
			this.modList.Width.Set(-25f, 1f);
			this.modList.Height.Set(-50f, 1f);
			this.modList.Top.Set(50f, 0f);
			this.modList.ListPadding = 5f;
			this.uIPanel.Append(this.modList);
			UIScrollbar uiscrollbar = new UIScrollbar();
			uiscrollbar.SetView(100f, 1000f);
			uiscrollbar.Height.Set(-50f, 1f);
			uiscrollbar.Top.Set(50f, 0f);
			uiscrollbar.HAlign = 1f;
			this.uIPanel.Append(uiscrollbar);
			this.modList.SetScrollbar(uiscrollbar);
			this.uIHeaderTextPanel = new UITextPanel<string>(Language.GetTextValue("tModLoader.MenuModBrowser"), 0.8f, true);
			this.uIHeaderTextPanel.HAlign = 0.5f;
			this.uIHeaderTextPanel.Top.Set(-35f, 0f);
			this.uIHeaderTextPanel.SetPadding(15f);
			this.uIHeaderTextPanel.BackgroundColor = new Color(73, 94, 171);
			this.uIElement.Append(this.uIHeaderTextPanel);
			this.reloadButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBGettingData"), 1f, false);
			this.reloadButton.Width.Set(-10f, 0.5f);
			this.reloadButton.Height.Set(25f, 0f);
			this.reloadButton.VAlign = 1f;
			this.reloadButton.Top.Set(-65f, 0f);
			this.reloadButton.OnMouseOver += UICommon.FadedMouseOver;
			this.reloadButton.OnMouseOut += UICommon.FadedMouseOut;
			this.reloadButton.OnClick += this.ReloadList;
			this.uIElement.Append(this.reloadButton);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("UI.Back"), 1f, false);
			uitextPanel.Width.Set(-10f, 0.5f);
			uitextPanel.Height.Set(25f, 0f);
			uitextPanel.VAlign = 1f;
			uitextPanel.Top.Set(-20f, 0f);
			uitextPanel.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel.OnClick += UIModBrowser.BackClick;
			this.uIElement.Append(uitextPanel);
			this.clearButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBClearSpecialFilter", "??"), 1f, false);
			this.clearButton.Width.Set(-10f, 0.5f);
			this.clearButton.Height.Set(25f, 0f);
			this.clearButton.HAlign = 1f;
			this.clearButton.VAlign = 1f;
			this.clearButton.Top.Set(-65f, 0f);
			this.clearButton.BackgroundColor = Color.Purple * 0.7f;
			this.clearButton.OnMouseOver += delegate(UIMouseEvent s, UIElement e)
			{
				UICommon.CustomFadedMouseOver(Color.Purple, s, e);
			};
			this.clearButton.OnMouseOut += delegate(UIMouseEvent s, UIElement e)
			{
				UICommon.CustomFadedMouseOut(Color.Purple * 0.7f, s, e);
			};
			this.clearButton.OnClick += delegate(UIMouseEvent s, UIElement e)
			{
				Interface.modBrowser.SpecialModPackFilter = null;
				Interface.modBrowser.SpecialModPackFilterTitle = null;
				Interface.modBrowser.updateNeeded = true;
				Main.PlaySound(12, -1, -1, 1, 1f, 0f);
			};
			this.downloadAllButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBDownloadAll"), 1f, false);
			this.downloadAllButton.Width.Set(-10f, 0.5f);
			this.downloadAllButton.Height.Set(25f, 0f);
			this.downloadAllButton.HAlign = 1f;
			this.downloadAllButton.VAlign = 1f;
			this.downloadAllButton.Top.Set(-20f, 0f);
			this.downloadAllButton.BackgroundColor = Color.Azure * 0.7f;
			this.downloadAllButton.OnMouseOver += delegate(UIMouseEvent s, UIElement e)
			{
				UICommon.CustomFadedMouseOver(Color.Azure, s, e);
			};
			this.downloadAllButton.OnMouseOut += delegate(UIMouseEvent s, UIElement e)
			{
				UICommon.CustomFadedMouseOut(Color.Azure * 0.7f, s, e);
			};
			this.downloadAllButton.OnClick += delegate(UIMouseEvent s, UIElement e)
			{
				this.DownloadMods(this.SpecialModPackFilter, this.SpecialModPackFilterTitle);
			};
			this.updateAllButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBUpdateAll"), 1f, false);
			this.updateAllButton.Width.Set(-10f, 0.5f);
			this.updateAllButton.Height.Set(25f, 0f);
			this.updateAllButton.HAlign = 1f;
			this.updateAllButton.VAlign = 1f;
			this.updateAllButton.Top.Set(-20f, 0f);
			this.updateAllButton.BackgroundColor = Color.Orange * 0.7f;
			this.updateAllButton.OnMouseOver += UICommon.FadedMouseOver;
			this.updateAllButton.OnMouseOut += UICommon.FadedMouseOut;
			this.updateAllButton.OnClick += delegate(UIMouseEvent s, UIElement e)
			{
				if (!this.loading)
				{
					List<string> specialModPackFilter = (from x in this.items
					where x.update && !x.updateIsDowngrade
					select x.mod).ToList<string>();
					this.DownloadMods(specialModPackFilter, Language.GetTextValue("tModLoader.MBUpdateAll"));
				}
			};
			base.Append(this.uIElement);
			UIElement uielement = new UIElement();
			uielement.Width.Set(0f, 1f);
			uielement.Height.Set(32f, 0f);
			uielement.Top.Set(10f, 0f);
			Texture2D texture = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.UIModBrowserIcons.png"));
			this.SortModeFilterToggle = new UICycleImage(texture, 6, 32, 32, 0, 0, 2);
			this.SortModeFilterToggle.setCurrentState((int)this.sortMode);
			this.SortModeFilterToggle.OnClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.sortMode = this.sortMode.NextEnum<ModBrowserSortMode>();
				this.updateNeeded = true;
			};
			this.SortModeFilterToggle.OnRightClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.sortMode = this.sortMode.PreviousEnum<ModBrowserSortMode>();
				this.updateNeeded = true;
			};
			this.SortModeFilterToggle.Left.Set(8f, 0f);
			this._categoryButtons.Add(this.SortModeFilterToggle);
			uielement.Append(this.SortModeFilterToggle);
			this.UpdateFilterToggle = new UICycleImage(texture, 3, 32, 32, 34, 0, 2);
			this.UpdateFilterToggle.setCurrentState((int)this.updateFilterMode);
			this.UpdateFilterToggle.OnClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.updateFilterMode = this.updateFilterMode.NextEnum<UpdateFilter>();
				this.updateNeeded = true;
			};
			this.UpdateFilterToggle.OnRightClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.updateFilterMode = this.updateFilterMode.PreviousEnum<UpdateFilter>();
				this.updateNeeded = true;
			};
			this.UpdateFilterToggle.Left.Set(44f, 0f);
			this._categoryButtons.Add(this.UpdateFilterToggle);
			uielement.Append(this.UpdateFilterToggle);
			this.ModSideFilterToggle = new UICycleImage(texture, 5, 32, 32, 170, 0, 2);
			this.ModSideFilterToggle.setCurrentState((int)this.modSideFilterMode);
			this.ModSideFilterToggle.OnClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.modSideFilterMode = this.modSideFilterMode.NextEnum<ModSideFilter>();
				this.updateNeeded = true;
			};
			this.ModSideFilterToggle.OnRightClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.modSideFilterMode = this.modSideFilterMode.PreviousEnum<ModSideFilter>();
				this.updateNeeded = true;
			};
			this.ModSideFilterToggle.Left.Set(80f, 0f);
			this._categoryButtons.Add(this.ModSideFilterToggle);
			uielement.Append(this.ModSideFilterToggle);
			UIPanel uipanel = new UIPanel();
			uipanel.Top.Set(0f, 0f);
			uipanel.Left.Set(-170f, 1f);
			uipanel.Width.Set(135f, 0f);
			uipanel.Height.Set(40f, 0f);
			uipanel.OnRightClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.filterTextBox.SetText("");
			};
			uielement.Append(uipanel);
			this.filterTextBox = new UIInputTextField(Language.GetTextValue("tModLoader.ModsTypeToSearch"));
			this.filterTextBox.Top.Set(5f, 0f);
			this.filterTextBox.Left.Set(-160f, 1f);
			this.filterTextBox.Width.Set(100f, 0f);
			this.filterTextBox.Height.Set(10f, 0f);
			this.filterTextBox.OnTextChange += delegate(object sender, EventArgs e)
			{
				this.updateNeeded = true;
			};
			uielement.Append(this.filterTextBox);
			this.SearchFilterToggle = new UICycleImage(texture, 2, 32, 32, 68, 0, 2);
			this.SearchFilterToggle.setCurrentState((int)this.searchFilterMode);
			this.SearchFilterToggle.OnClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.searchFilterMode = this.searchFilterMode.NextEnum<SearchFilter>();
				this.updateNeeded = true;
			};
			this.SearchFilterToggle.OnRightClick += delegate(UIMouseEvent a, UIElement b)
			{
				this.searchFilterMode = this.searchFilterMode.PreviousEnum<SearchFilter>();
				this.updateNeeded = true;
			};
			this.SearchFilterToggle.Left.Set(545f, 0f);
			this._categoryButtons.Add(this.SearchFilterToggle);
			uielement.Append(this.SearchFilterToggle);
			this.uIPanel.Append(uielement);
		}

		// Token: 0x06001A8A RID: 6794 RVA: 0x0042A934 File Offset: 0x00428B34
		public override void Draw(SpriteBatch spriteBatch)
		{
			base.Draw(spriteBatch);
			for (int i = 0; i < this._categoryButtons.Count; i++)
			{
				if (this._categoryButtons[i].IsMouseHovering)
				{
					string text;
					switch (i)
					{
					case 0:
						text = this.sortMode.ToFriendlyString();
						break;
					case 1:
						text = this.updateFilterMode.ToFriendlyString();
						break;
					case 2:
						text = this.modSideFilterMode.ToFriendlyString();
						break;
					case 3:
						text = this.searchFilterMode.ToFriendlyString();
						break;
					default:
						text = "None";
						break;
					}
					float x = Main.fontMouseText.MeasureString(text).X;
					Vector2 vector = new Vector2((float)Main.mouseX, (float)Main.mouseY) + new Vector2(16f);
					if (vector.Y > (float)(Main.screenHeight - 30))
					{
						vector.Y = (float)(Main.screenHeight - 30);
					}
					if (vector.X > (float)Main.screenWidth - x)
					{
						vector.X = (float)Main.screenWidth - x - 30f;
					}
					Utils.DrawBorderStringFourWay(spriteBatch, Main.fontMouseText, text, vector.X, vector.Y, new Color((int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor), Color.Black, Vector2.Zero, 1f);
					return;
				}
			}
			if (this.updateAvailable)
			{
				this.updateAvailable = false;
				Interface.updateMessage.SetMessage(this.updateText);
				Interface.updateMessage.SetGotoMenu(10007);
				Interface.updateMessage.SetURL(this.updateURL);
				Main.menuMode = 10012;
			}
			UILinkPointNavigator.Shortcuts.BackButtonCommand = 101;
		}

		// Token: 0x06001A8B RID: 6795 RVA: 0x0042AADC File Offset: 0x00428CDC
		public static void BackClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(11, -1, -1, 1, 1f, 0f);
			Main.menuMode = 0;
			if (Interface.modBrowser.aModUpdated && !ModLoader.dontRemindModBrowserUpdateReload)
			{
				Interface.advancedInfoMessage.SetMessage(Language.GetTextValue("tModLoader.ReloadModsReminder"));
				Interface.advancedInfoMessage.SetGotoMenu(0);
				Interface.advancedInfoMessage.SetAltMessage(Language.GetTextValue("tModLoader.DontShowAgain"));
				Interface.advancedInfoMessage.SetAltAction(delegate
				{
					ModLoader.dontRemindModBrowserUpdateReload = true;
					Main.SaveSettings();
				});
				Main.menuMode = 10014;
			}
			else if (Interface.modBrowser.aNewModDownloaded && !ModLoader.dontRemindModBrowserDownloadEnable)
			{
				Interface.advancedInfoMessage.SetMessage(Language.GetTextValue("tModLoader.EnableModsReminder"));
				Interface.advancedInfoMessage.SetGotoMenu(0);
				Interface.advancedInfoMessage.SetAltMessage(Language.GetTextValue("tModLoader.DontShowAgain"));
				Interface.advancedInfoMessage.SetAltAction(delegate
				{
					ModLoader.dontRemindModBrowserDownloadEnable = true;
					Main.SaveSettings();
				});
				Main.menuMode = 10014;
			}
			Interface.modBrowser.aModUpdated = false;
			Interface.modBrowser.aNewModDownloaded = false;
		}

		// Token: 0x06001A8C RID: 6796 RVA: 0x00012F5C File Offset: 0x0001115C
		private void ReloadList(UIMouseEvent evt, UIElement listeningElement)
		{
			if (!this.loading)
			{
				Main.PlaySound(10, -1, -1, 1, 1f, 0f);
				this.PopulateModBrowser();
			}
		}

		// Token: 0x06001A8D RID: 6797 RVA: 0x0042AC10 File Offset: 0x00428E10
		public override void Update(GameTime gameTime)
		{
			base.Update(gameTime);
			if (!this.updateNeeded)
			{
				return;
			}
			this.updateNeeded = false;
			if (!this.loading)
			{
				this.uIPanel.RemoveChild(this.uILoader);
			}
			this.filter = this.filterTextBox.currentString;
			this.modList.Clear();
			this.modList.AddRange(from item in this.items
			where item.PassFilters()
			select item);
			this.uIElement.RemoveChild(this.updateAllButton);
			if (this.SpecialModPackFilter == null)
			{
				if (this.items.Count((UIModDownloadItem x) => x.update && !x.updateIsDowngrade) > 0)
				{
					this.uIElement.Append(this.updateAllButton);
				}
			}
		}

		// Token: 0x06001A8E RID: 6798 RVA: 0x00012F81 File Offset: 0x00011181
		public override void OnActivate()
		{
			Main.clrInput();
			if (!this.loading && this.items.Count <= 0)
			{
				this.PopulateModBrowser();
			}
		}

		// Token: 0x06001A8F RID: 6799 RVA: 0x00012FA4 File Offset: 0x000111A4
		internal void ClearItems()
		{
			this.items.Clear();
		}

		// Token: 0x06001A90 RID: 6800 RVA: 0x0042ACF8 File Offset: 0x00428EF8
		private void PopulateModBrowser()
		{
			this.loading = true;
			this.SpecialModPackFilter = null;
			this.SpecialModPackFilterTitle = null;
			this.reloadButton.SetText(Language.GetTextValue("tModLoader.MBGettingData"));
			this.SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser"));
			this.uIPanel.Append(this.uILoader);
			this.modList.Clear();
			this.items.Clear();
			this.modList.Deactivate();
			try
			{
				ServicePointManager.Expect100Continue = false;
				string uriString = "http://javid.ddns.net/tModLoader/listmods.php";
				NameValueCollection data = new NameValueCollection
				{
					{
						"modloaderversion",
						ModLoader.versionedName
					},
					{
						"platform",
						ModLoader.compressedPlatformRepresentation
					}
				};
				using (WebClient webClient = new WebClient())
				{
					ServicePointManager.ServerCertificateValidationCallback = ((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) => true);
					webClient.UploadValuesCompleted += this.UploadComplete;
					webClient.UploadValuesAsync(new Uri(uriString), "POST", data);
				}
			}
			catch (WebException ex)
			{
				if (ex.Status == WebExceptionStatus.Timeout)
				{
					this.SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBBusy")));
				}
				else if (ex.Status == WebExceptionStatus.ProtocolError)
				{
					HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response;
					HttpStatusCode statusCode = httpWebResponse.StatusCode;
					this.SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", httpWebResponse.StatusCode));
				}
			}
			catch (Exception e)
			{
				ErrorLogger.LogModBrowserException(e);
			}
		}

		// Token: 0x06001A91 RID: 6801 RVA: 0x0042AEC8 File Offset: 0x004290C8
		public void UploadComplete(object sender, UploadValuesCompletedEventArgs e)
		{
			if (e.Error != null)
			{
				if (!e.Cancelled)
				{
					HttpStatusCode httpStatusCode = this.GetHttpStatusCode(e.Error);
					if (httpStatusCode == HttpStatusCode.ServiceUnavailable)
					{
						this.SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBBusy")));
					}
					else
					{
						this.SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBUnknown")));
					}
				}
				this.loading = false;
				this.reloadButton.SetText(Language.GetTextValue("tModLoader.MBReloadBrowser"));
				return;
			}
			if (!e.Cancelled)
			{
				this.reloadButton.SetText(Language.GetTextValue("tModLoader.MBPopulatingBrowser"));
				byte[] result = e.Result;
				string response = Encoding.UTF8.GetString(result);
				if (SynchronizationContext.Current == null)
				{
					SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
				}
				Task.Factory.StartNew<LocalMod[]>(new Func<LocalMod[]>(ModLoader.FindMods)).ContinueWith(delegate(Task<LocalMod[]> task)
				{
					this.PopulateFromJSON(task.Result, response);
					this.loading = false;
					this.reloadButton.SetText(Language.GetTextValue("tModLoader.MBReloadBrowser"));
				}, TaskScheduler.FromCurrentSynchronizationContext());
			}
		}

		// Token: 0x170001C6 RID: 454
		// (get) Token: 0x06001A92 RID: 6802 RVA: 0x0042AFF8 File Offset: 0x004291F8
		internal static bool PlatformSupportsTls12
		{
			get
			{
				foreach (object obj in Enum.GetValues(typeof(SecurityProtocolType)))
				{
					if (((SecurityProtocolType)obj).GetHashCode() == 3072)
					{
						return true;
					}
				}
				return false;
			}
		}

		// Token: 0x06001A93 RID: 6803 RVA: 0x0042B070 File Offset: 0x00429270
		private void PopulateFromJSON(LocalMod[] installedMods, string json)
		{
			string str = UIModBrowser.PlatformSupportsTls12 ? "&tls12=y" : "";
			try
			{
				JObject jobject;
				try
				{
					jobject = JObject.Parse(json);
				}
				catch (Exception innerException)
				{
					throw new Exception("Bad JSON: " + json, innerException);
				}
				JObject jobject2 = (JObject)jobject["update"];
				if (jobject2 != null)
				{
					this.updateAvailable = true;
					this.updateText = (string)jobject2["message"];
					this.updateURL = (string)jobject2["url"];
				}
				JArray jarray = (JArray)jobject["modlist"];
				foreach (JObject jobject3 in jarray.Children<JObject>())
				{
					string displayname = (string)jobject3["displayname"];
					string name = (string)jobject3["name"];
					string text = (string)jobject3["version"];
					string author = (string)jobject3["author"];
					string download = (string)jobject3["download"] + str;
					int downloads = (int)jobject3["downloads"];
					int hot = (int)jobject3["hot"];
					string timeStamp = (string)jobject3["updateTimeStamp"];
					string modreferences = (string)jobject3["modreferences"];
					ModSide modside = ModSide.Both;
					string modIconURL = (string)jobject3["iconurl"];
					string a = (string)jobject3["modside"];
					if (a == "Client")
					{
						modside = ModSide.Client;
					}
					if (a == "Server")
					{
						modside = ModSide.Server;
					}
					if (a == "NoSync")
					{
						modside = ModSide.NoSync;
					}
					bool update = false;
					bool updateIsDowngrade = false;
					LocalMod localMod = installedMods.FirstOrDefault((LocalMod m) => m.Name == name);
					if (localMod != null)
					{
						Version v = new Version(text.Substring(1));
						if (v > localMod.modFile.version)
						{
							update = true;
						}
						else if (v < localMod.modFile.version)
						{
							updateIsDowngrade = (update = true);
						}
					}
					UIModDownloadItem item = new UIModDownloadItem(displayname, name, text, author, modreferences, modside, modIconURL, download, downloads, hot, timeStamp, update, updateIsDowngrade, localMod);
					this.items.Add(item);
				}
				this.updateNeeded = true;
			}
			catch (Exception e)
			{
				ErrorLogger.LogModBrowserException(e);
			}
		}

		// Token: 0x06001A94 RID: 6804 RVA: 0x0042B358 File Offset: 0x00429558
		private void DownloadMods(List<string> specialModPackFilter, string SpecialModPackFilterTitle)
		{
			Main.PlaySound(12, -1, -1, 1, 1f, 0f);
			Interface.downloadMods.SetDownloading(SpecialModPackFilterTitle);
			Interface.downloadMods.SetModsToDownload(specialModPackFilter, this.items);
			Interface.modBrowser.updateNeeded = true;
			Main.menuMode = 10020;
		}

		// Token: 0x06001A95 RID: 6805 RVA: 0x00012FB1 File Offset: 0x000111B1
		private void SetHeading(string heading)
		{
			this.uIHeaderTextPanel.SetText(heading, 0.8f, true);
			this.uIHeaderTextPanel.Recalculate();
		}

		// Token: 0x06001A96 RID: 6806 RVA: 0x00427A1C File Offset: 0x00425C1C
		private HttpStatusCode GetHttpStatusCode(Exception err)
		{
			if (err is WebException)
			{
				WebException ex = (WebException)err;
				if (ex.Response is HttpWebResponse)
				{
					HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response;
					return httpWebResponse.StatusCode;
				}
			}
			return (HttpStatusCode)0;
		}

		// Token: 0x040017AC RID: 6060
		public UIList modList;

		// Token: 0x040017AD RID: 6061
		private readonly List<UIModDownloadItem> items = new List<UIModDownloadItem>();

		// Token: 0x040017AE RID: 6062
		internal bool updateNeeded;

		// Token: 0x040017AF RID: 6063
		public UIModDownloadItem selectedItem;

		// Token: 0x040017B0 RID: 6064
		private UIElement uIElement;

		// Token: 0x040017B1 RID: 6065
		private UIPanel uIPanel;

		// Token: 0x040017B2 RID: 6066
		private UILoaderAnimatedImage uILoader;

		// Token: 0x040017B3 RID: 6067
		public UITextPanel<string> uIHeaderTextPanel;

		// Token: 0x040017B4 RID: 6068
		internal UIInputTextField filterTextBox;

		// Token: 0x040017B5 RID: 6069
		internal readonly List<UICycleImage> _categoryButtons = new List<UICycleImage>();

		// Token: 0x040017B6 RID: 6070
		private UITextPanel<string> reloadButton;

		// Token: 0x040017B7 RID: 6071
		private UITextPanel<string> clearButton;

		// Token: 0x040017B8 RID: 6072
		private UITextPanel<string> downloadAllButton;

		// Token: 0x040017B9 RID: 6073
		private UITextPanel<string> updateAllButton;

		// Token: 0x040017BA RID: 6074
		public UICycleImage UpdateFilterToggle;

		// Token: 0x040017BB RID: 6075
		public UICycleImage SortModeFilterToggle;

		// Token: 0x040017BC RID: 6076
		public UICycleImage ModSideFilterToggle;

		// Token: 0x040017BD RID: 6077
		public UICycleImage SearchFilterToggle;

		// Token: 0x040017BE RID: 6078
		public bool loading;

		// Token: 0x040017BF RID: 6079
		public ModBrowserSortMode sortMode = ModBrowserSortMode.RecentlyUpdated;

		// Token: 0x040017C0 RID: 6080
		public UpdateFilter updateFilterMode = UpdateFilter.Available;

		// Token: 0x040017C1 RID: 6081
		public SearchFilter searchFilterMode;

		// Token: 0x040017C2 RID: 6082
		public ModSideFilter modSideFilterMode;

		// Token: 0x040017C3 RID: 6083
		internal string filter;

		// Token: 0x040017C4 RID: 6084
		private bool updateAvailable;

		// Token: 0x040017C5 RID: 6085
		private string updateText;

		// Token: 0x040017C6 RID: 6086
		private string updateURL;

		// Token: 0x040017C7 RID: 6087
		public bool aModUpdated;

		// Token: 0x040017C8 RID: 6088
		public bool aNewModDownloaded;

		// Token: 0x040017C9 RID: 6089
		private string _specialModPackFilterTitle;

		// Token: 0x040017CA RID: 6090
		private List<string> _specialModPackFilter;
	}
}
